<template>
  <div class="app-container bg-gray">
    <el-card class="box-1">
      <div class="header-reamrk">
        <!--<el-row><i class="el-icon-warning-outline"/> 提示：为提供安全和良好的下载体验，您的文件生成后将暂存在腾讯云COS中，三天后自动删除。</el-row>-->
        <el-row>导出记录</el-row>
      </div>
      <el-table v-loading="tableLoading" :data="tableData" :max-height="tableMaxHeight" highlight-current-row @sort-change="handleSortChange">
        <el-table-column prop="type" label="文件类型" width="120"/>
        <el-table-column prop="name" label="文件名称" min-width="250"/>
        <el-table-column prop="status" label="状态" width="110">
          <template slot-scope="scope">
            <slot v-if="scope.row.status===3">
              <i class="el-icon-check"/> 成功
            </slot>
            <slot v-else>
              <i class="el-icon-loading"/> 等待下发
            </slot>
          </template>
        </el-table-column>
        <el-table-column prop="userName" label="创建人" width="120"/>
        <el-table-column prop="generate_time" label="文件生成时间" width="200"/>
        <el-table-column prop="down_time" label="最近下载时间" width="200"/>
        <el-table-column label="操作" min-width="160">
          <template slot-scope="scope">
            <el-button :disabled="scope.row.status!==3" type="text" @click="bindDownload(scope.row.id, scope.row.address)">下载</el-button>
            <el-button :disabled="scope.row.status!==3" type="text" @click="$router.push(`./analysisOrder?id=${scope.row.id}`)">查看</el-button>
            <!--275-->
            <el-button :disabled="scope.row.status!==3" type="text" @click="$router.push(`./analysis?id=${scope.row.id}`)">分析</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        :current-page.sync="currentPage"
        :page-size="pageSize"
        :page-sizes="pageSizes"
        :total="total"
        class="pagination"
        layout="total, sizes, prev, pager, next, jumper"
        @current-change="handleCurrentChange"
        @size-change="handleSizeChange"/>
    </el-card>
  </div>
</template>

<script>
import { handleSortChange, handleSizeChange, handleCurrentChange, columnCheck, parseTime } from '@/utils/table'

export default {
  data() {
    return {
      // 表格相关数据
      tableMaxHeight: document.documentElement.clientHeight - 280,
      tableLoading: false,
      currentPage: 1,
      pageSize: this.$store.getters.userInfo.pageSize,
      pageSizes: [10, 20, 50, 100, 1000],
      total: 0,
      tableData: [],
      timer: null
    }
  },
  mounted() {
    this.getData();
      this.timer = setInterval(()=>{
        this.getData();
      }, 5000)
  },
  methods: {
    handleCurrentChange, handleSizeChange, handleSortChange, columnCheck, parseTime,
    getData(order) {
      order || (order = {})
      const url = 'tencent/getAnalysisList'
      const data = {
        page_no: this.currentPage,
        page_size: this.pageSize
      }
      order.sortName && (data.sortName = order.sortName)
      order.sortOrder && (data.sortOrder = order.sortOrder)
      this.$store.dispatch('GetConnect', { url, data }).then(res => {
        this.tableData = res.data.rows
        this.total = res.data.total
      }).catch(e => {
        this.$message.error(e.msg + ',请刷新或联系管理员')
      })
    },

    bindDownload(id, path) {
      window.open(path);
      const url = 'tencent/updateTime'
      const data = {
        id: id
      }
      this.$store.dispatch('GetConnect', {url, data}).then(() => {
        this.getData()
      }).catch(e => {
        this.$message.error('操作失败,请刷新或联系管理员')
      })
    }
  }
}
</script>

<style lang="scss" type="text/scss" scoped>
@import '../../../../styles/index.scss';
.box-1 {
  .header-reamrk {
    padding-bottom: 15px;

    .el-row {
      border: 1px solid $panGreen;
      border-radius: 4px;
      background-color: rgba(22, 219, 195, 0.11);
      padding: 10px 12px;
      font-size: 12px;
      color: $text43;
    }
  }
}
</style>

